/*
 人员工作范围
 polygon
*/
import GPS from '@/utils/gps'
export default class CheckArea {
  constructor(map, list) {
    this.map = map;
    this.list = JSON.parse(JSON.stringify(list));
    this.polygonLayer = []
    this.init()
  }

  init() {
    const polygons = []
    this.list.forEach(item => {
      if(item.locations) {

          const path = JSON.parse(item.locations)
          if(item.type == 2) {
              const polygon = new AMap.Polygon({
                path: path.map(item => GPS.WGS84toGCJ02(...item)),
                strokeColor: '#f00',
                fillColor: '#ff0',
                fillOpacity: 0.5,
                strokeStyle: "dashed",
                strokeDasharray: [10, 10],
                title: item.title
              });
              polygons.push(polygon)
          }
          if(item.type == 1) {
            var circle = new AMap.Circle({
                center: GPS.WGS84toGCJ02(...path), //圆心
                radius: 1000, //半径
                borderWeight: 3, //描边的宽度
                strokeColor: "#f00", //轮廓线颜色
                strokeOpacity: 1, //轮廓线透明度
                strokeWeight: 2, //轮廓线宽度
                fillOpacity: 0.4, //圆形填充透明度
                strokeStyle: "dashed", //轮廓线样式
                strokeDasharray: [10, 10],
                fillColor: "#ff0", //圆形填充颜色
                zIndex: 50, //圆形的叠加顺序
              });
              polygons.push(circle)
          }
      }
    })


    this.polygonLayer = polygons
    this.map.add(this.polygonLayer)
    this.map.setFitView()
  }

  destroy() {
    if(this.polygonLayer.length>0) {
      this.map.remove(this.polygonLayer)
      this.polygonLayer.length = 0
    }
  }
}
